home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
pascal
/
fielddh.exe
/
STR_STF.PAS
< prev
Wrap
Pascal/Delphi Source File
|
1992-04-22
|
19KB
|
512 lines
UNIT STR_STF;
{** STRING Definition and OPERATIONS ***}
{$O-,F+,D-}
INTERFACE
{**************************************************************}
{* Trim removes leading/trailing blanks. *}
{* *}
{**************************************************************}
FUNCTION TRIM (Str : string) : string;
FUNCTION TRIM_Leading_Only (Str : string) : string;
FUNCTION TRIM_Trailing_Only (Str : string) : string;
FUNCTION TRIM_Quotes (Str : string) : string;
{**************************************************************}
{* Right_Justify adds leading blanks. *}
{* NOTE: does not handle cases when *}
{* Size_To_Be < ACTUAL NUMBER OF CHARACTERS *}
{**************************************************************}
FUNCTION Right_Justify (Str : string; Size_To_Be : integer) : string;
{***************************************************************}
{* Center_Str centers the characters in the string based *}
{* upon the size/midpoint specified. *}
{***************************************************************}
FUNCTION Center_Str (Str : string; Output_Size : integer) : string;
{**************************************************************}
{* Change_Case changes the case of the string to UPPER. *}
{* *}
{**************************************************************}
FUNCTION CHANGE_CASE (Str : string) : string;
FUNCTION Lower_Case (Str : string) : string;
{**************************************************************}
{* Int_To_Str returns the number converted into ascii chars. *}
{* *}
{**************************************************************}
FUNCTION Int_To_Str (Num : LongInt) : string;
{**************************************************************}
{* Find_Char returns the position of the char *}
{* *}
{**************************************************************}
FUNCTION Find_Char (Str : string;
Char_Is : char;
Start_At : integer) : INTEGER;
{**************************************************************}
{* Delete_The_Char delete all occurances of the char *}
{* *}
{**************************************************************}
FUNCTION Delete_The_Char
(Str : string;
Char_Is : char) : string;
{**************************************************************}
{* Replace_Str_Into inserts the small string into the *}
{* org_str at the position specified *}
{**************************************************************}
FUNCTION Replace_Str_Into (Org_Str : String;
Small_Str : string;
Start, Stop : integer) : string;
{**************************************************************}
{* procedure Get_Word_Around_Position *}
{* returns the word based AROUND the position specified *}
{* Searches for blanks around the start_pos *}
{* looking left then right. *}
{**************************************************************}
function Get_Word_Around_Position
(Str : string;
Start_Pos : integer;
Leftmost_Char_Boundry : integer;
Rightmost_Char_Boundry : integer;
VAR Found_Left_Pos : integer;
VAR Found_Word_Size : integer) : string;
{**************************************************************}
{* returns a string with duplicate chars deleted. *}
{**************************************************************}
function Delete_Duplicate_Chars_In_Str (Str : string;
Limit_In_A_Row : byte): string;
{**************************************************************}
{* returns a string filled with the character specified *}
{**************************************************************}
function Fill_String(Len : Byte; Ch : Char) : String;
{**************************************************************}
{* Truncates a string to a specified length *}
{**************************************************************}
function Trunc_Str(TString : String; Len : Byte) : String;
{**************************************************************}
{* Pads a string to a specified length with a specified character }
{**************************************************************}
function Pad_Char(PString : String; Ch : Char; Len : Byte) : String;
{**************************************************************}
{* Left-justify a string within a certain width *}
{**************************************************************}
function Left_Justify_Str (S : String; Width : Byte) : String;
{**************************************************************}
{**************************************************************}
{**************************************************************}
IMPLEMENTATION
{**************************************************************************}
function Min(N1, N2 : Longint) : Longint;
{ Returns the smaller of two numbers }
begin
if N1 <= N2 then
Min := N1
else
Min := N2;
end; { Min }
{**************************************************************************}
function Max(N1, N2 : Longint) : Longint;
{ Returns the larger of two numbers }
begin
if N1 >= N2 then
Max := N1
else
Max := N2;
end; { Max }
{**************************************************************}
{* returns a string filled with the character specified *}
{**************************************************************}
function Fill_String(Len : Byte; Ch : Char) : String;
var
S : String;
begin
IF (Len > 0) THEN
BEGIN
S[0] := Chr(Len);
FillChar(S[1], Len, Ch);
Fill_String := S;
END
ELSE Fill_String := '';
end; { FillString }
{**************************************************************}
{* Truncates a string to a specified length *}
{**************************************************************}
function Trunc_Str(TString : String; Len : Byte) : String;
begin
if (Length(TString) > Len) then
begin
{Delete(TString, Succ(Len), Length(TString) - Len);}
{Move(TString[Succ(Len)+(LENGTH(TString)-Len)], TString[Succ(Len)],
Succ(Length(TString)) - Succ(Len) - Length(TString) - Len));}
Move(TString[LENGTH(TString)+1], TString[Succ(Len)], 2*Len);
Dec(TString[0], Length(TString) - Len);
end;
Str_Stf.Trunc_Str := TString;
end; { TruncStr }
{**************************************************************}
{* Pads a string to a specified length with a specified character }
{**************************************************************}
function Pad_Char(PString : String; Ch : Char; Len : Byte) : String;
var
CurrLen : Byte;
begin
CurrLen := Min(Length(PString), Len);
PString[0] := Chr(Len);
FillChar(PString[Succ(CurrLen)], Len - CurrLen, Ch);
Pad_Char := PString;
end; { PadChar }
{**************************************************************}
{* Left-justify a string within a certain width *}
{**************************************************************}
function Left_Justify_Str(S : String; Width : Byte) : String;
begin
Left_Justify_Str := Str_Stf.Pad_Char(S, ' ', Width);
end; { Left_Justify_Str }
{**************************************************************}
{* Trim removes leading/trailing blanks. *}
{*